package MyText1;

import java.util.Arrays;

public class MyStack {
    public int[] arr;
    public int size;
    public MyStack() {
        this.arr = new int[10];
    }
    private void ensureCapacity(){
        if(isFull()){
            arr= Arrays.copyOf(arr,2*arr.length);
        }
    }
    private boolean isFull(){
        return size==arr.length;
    }
    public int push(int val){
        ensureCapacity();
        arr[size++]=val;
        return val;
    }

    public boolean empty(){
        return size==0;
    }

    public  int size(){
        return size;
    }

    public int pop()throws EmptyException {
        if(empty()){
            throw new EmptyException("栈是空的！");
        }
        return arr[--size];
    }
    public int peek()throws EmptyException{
        if(empty()){
            throw new EmptyException("栈是空的！");
        }
        return arr[size-1];
    }
}
